package com.zeta.eduservice.service.impl;

import com.zeta.eduservice.entity.excel.QuestionExcel;
import com.zeta.eduservice.entity.question.EduChapter;
import com.zeta.eduservice.entity.question.EduQuestion;
import com.zeta.eduservice.entity.vo.Ata;
import com.zeta.eduservice.entity.vo.QuestionQuery;
import com.zeta.eduservice.entity.vo.QuestionUploadVo;
import com.zeta.eduservice.entity.vo.questionVo;
import com.zeta.eduservice.entity.vo.front.EduQuestionVo;
import com.zeta.eduservice.entity.vo.front.PdfQuestionVo;
import com.zeta.eduservice.listener.UploadQuestionExcelListener;
import com.zeta.eduservice.mapper.EduQuestionMapper;
import com.zeta.eduservice.service.ChapterAQuestionTypeSysAndChoicequestionService;
import com.zeta.eduservice.service.ChapterAQuestionTypeSysAndQuestionService;
import com.zeta.eduservice.service.EduChapterService;
import com.zeta.eduservice.service.EduCoursequestionlistInfoService;
import com.zeta.eduservice.service.EduQuestionChoiceService;
import com.zeta.eduservice.service.EduQuestionService;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 试题 服务实现类
 * </p>
 *
 * @author zeta
 * @since 2020-08-25
 */
@Service
public  class EduQuestionServiceImpl extends ServiceImpl<EduQuestionMapper, EduQuestion> implements EduQuestionService {

	@Autowired
	EduChapterService chapterService;

	@Override
	public List<EduQuestion> getsByCourseId(String courseId) {
		List<EduQuestion> getsByCourseId = baseMapper.getsByCourseId(courseId);
		return getsByCourseId;
	}

	@Override
	public List<EduQuestionVo> getsByfolderId(String folderId) {
		List<EduQuestionVo> getsByfolderId = baseMapper.getsByfolderId(folderId);
		return getsByfolderId;
	}

	@Override
	public List<PdfQuestionVo> getsPdfByfolderId(String folderId) {
		List<PdfQuestionVo> getsByfolderId = baseMapper.getsPdfByfolderId(folderId);
		return getsByfolderId;
	}

	@Override
	public void upload(MultipartFile file,QuestionUploadVo currChapterId, EduQuestionService questionService,ChapterAQuestionTypeSysAndQuestionService chapterAQuestionTypeSysAndquestionService)
			throws IOException {
		InputStream in = file.getInputStream();
		EasyExcel.read(in, QuestionExcel.class, new UploadQuestionExcelListener(questionService,chapterAQuestionTypeSysAndquestionService, currChapterId)).sheet()
				.doRead();
		
		
	}
	@Override
	public List<questionVo> getsByMidId(Page<questionVo> page,QuestionQuery searchObj) {
	
		List<questionVo> byMidId = baseMapper.getByMidId(page,searchObj.getTypeId());
	return byMidId;
	}
	@Override
	public List<questionVo> getQuestionsByQuestionTypeSys(Page<questionVo> page,QuestionQuery searchObj) {
		
		List<questionVo> byMidId = baseMapper.GetQuestionsByQuestionTypeSys(page, searchObj.getCourseId(), searchObj.getTypeSys());
	return byMidId;
	}
	
	@Override
	public List<questionVo> getByPaperTypeId(Page<questionVo> page,QuestionQuery searchObj) {
		
		List<questionVo> byMidId = baseMapper.getByPaperTypeId(page, searchObj.getTypeId());
	return byMidId;
	}
	@Override
	public List<questionVo> getByPaperTypeId(QuestionQuery searchObj) {
		
		List<questionVo> byMidId = baseMapper.getByPaperTypeId( searchObj.getTypeId());
	return byMidId;
	}
}
